#include <BaseUnitConversion.h>
#include <iostream>

template <typename Unit>
BaseUnitConversion<Unit>::BaseUnitConversion(const std::string& name, unsigned int factor, const Unit *referenceUnit)
    : name(name)
    , factor(factor)
    , referenceUnit(referenceUnit)
{
}

template <typename Unit>
unsigned int BaseUnitConversion<Unit>::toBase() const
{
    return (referenceUnit != 0) ? this->factor * referenceUnit->toBase() : this->factor;
}

template <typename Unit>
void  BaseUnitConversion<Unit>::outputString(std::stringstream& os, const Unit* unit, unsigned int amountInBase) const
{
    unsigned int curruntfactor = unit->toBase();

    if (amountInBase / curruntfactor != 0){
        os << amountInBase / curruntfactor << " " << unit->baseUnitConversion.name << " ";
    }

    if (unit->baseUnitConversion.referenceUnit != 0)
    {
        outputString(os, unit->baseUnitConversion.referenceUnit, amountInBase % curruntfactor);
    }
}
